package com.sample.utils;

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.widget.Toast;

public class AcceseTokenTask extends AsyncTask<Uri, Void, Void> {
	public Context mContext;
	private OAuthConsumer consumer;
	private OAuthProvider provider;
	
	public AcceseTokenTask( Context mContext, OAuthConsumer consumer, OAuthProvider provider){
		
		this.mContext = mContext;
		this.consumer = consumer;
		this.provider = provider;
		
		 
	}
	@Override
	protected Void doInBackground(Uri... params) {
		
		try {
			final String oauth_verifier = params[0].getQueryParameter( OAuth.OAUTH_VERIFIER );
			System.out.println("oauth_verifier:" + oauth_verifier);
			
			provider.retrieveAccessToken(consumer, oauth_verifier);
			
			System.out.println( "token:" + consumer.getToken());
			System.out.println( "tokenSecret:" + consumer.getTokenSecret());
			
			System.out.println("Request_Token====>Retrive====>AccessToken Completed!!");
		} catch (OAuthMessageSignerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthNotAuthorizedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthExpectationFailedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthCommunicationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
